package com.jixin.jdpay;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang3.time.DateFormatUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.jixin.jdpay.request.SignJdPayRequest;

public class JdPayParamUtils {
	
	/**
	 * 网银在线签约参数
	 * @param request
	 * @return
	 */
	public static Map<String, Object> buildSignParam(SignJdPayRequest request){
		//签约参数
		Map<String, Object> params = new HashMap<>();
		params.put("card_bank", 		request.getBankCode());
		params.put("card_no", 			request.getCardNo());
		params.put("card_name", 		request.getName());
		params.put("card_idno", 		request.getIdno());
		params.put("card_phone", 		request.getPhone());
		params.put("trade_id",  		request.getOrderNo());
		params.put("trade_amount", 		request.getAmount());
		params.put("card_exp", 			"");
		params.put("card_cvv2", 		"");
		params.put("card_type", 		"D");
		params.put("card_idtype", 		"I");
		params.put("trade_type", 		"V");
		params.put("trade_currency", 	"CNY");
		return params;
	}
	
	
	public static Map<String, Object> buildTradeParam(String signRequestInfo, String code){
		Map<String, Object> params = null;
		params = JSON.parseObject(signRequestInfo, new TypeReference<TreeMap<String, Object>>() {});
		params.put("trade_code", 		code);
		params.put("trade_notice", 		JdPayConfigUtil.getNOTIFY_URL());
		params.put("trade_date", 		DateFormatUtils.format(new Date(), "yyyyMMdd"));
		params.put("trade_time", 		DateFormatUtils.format(new Date(), "HHmmss"));
		params.put("card_type", 		"D");
		params.put("trade_currency", 	"CNY");
		params.put("trade_type", 		"S");
		params.put("card_idtype", 		"I");
		params.put("card_exp", 			"");
		params.put("card_cvv2", 		"");
		return params;
	}

}
